from typing import Optional

from fastapi import APIRouter, Depends
from fastapi_amis_admin.globals.deps import AsyncSess, SyncSess
from fastapi_amis_admin.models import Field

from backend.apps.common import PageParams, ApiResult, PageResult, CommonUtil
from .models import SysDept, DeptQueryParams
from .service import DeptService as deptService
from ..security.service import get_current_user

router = APIRouter()


@router.post("/page")
def page(params: DeptQueryParams, sess: SyncSess):
    return deptService.page(params, sess)


@router.get("/detail", response_model=ApiResult)
def detail(id: int, sess: SyncSess):
    return ApiResult(data=deptService.detail(id, sess))

@router.post("/save")
def save(sess: SyncSess, data: SysDept):
    deptService.save(sess, data)
    return ApiResult()


@router.put("/update")
def update(data: SysDept, sess: SyncSess):
    deptService.update(data, sess)
    return ApiResult()


@router.delete("/delete")
def delete(id: int, sess: SyncSess):
    deptService.delete(id, sess)
    return ApiResult()